package com.example.springboottrackdemo.controller;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


/**
 * @author 陳樂
 * @version 1.0.0
 * @ClassName TestController.java
 * @Description TODO
 * @createTime 2023年02月18日 21:12:00
 */
@RestController
@Slf4j
public class TestController {

    private final static Logger logger = LoggerFactory.getLogger(TestController.class);

    @Autowired
    private Executor myExecutor;

    @GetMapping("/test")
    public void test() {
        logger.info("这是一个info");
        logger.error("这是一个error");
    }


    @GetMapping("/multThread")
    public void multThread() {
        logger.info("线程开始");

//        ExecutorService service = Executors.newFixedThreadPool(20);
//        service.submit(new Runnable() {
//            @Override
//            public void run() {
//                logger.info("多线程内部");
//            }
//        });

        myExecutor.execute(new Runnable() {
            @Override
            public void run() {
                logger.info("多线程内部");
            }
        });

    }
}
